#ifndef GRAPHICSIMAGEITEM_H
#define GRAPHICSIMAGEITEM_H

#include <QGraphicsObject>
#include "iplqimage.h"

const int EDGEWIDTH = 20;
const int EDGEHEIGHT = 20;

class QString;

class GraphicsImageItem : public QGraphicsObject
{
    Q_OBJECT
public:
    explicit GraphicsImageItem(QString *rawFile, int width, int height, QGraphicsObject *parent = 0);
    ~GraphicsImageItem();

    QRectF boundingRect() const;
    QPainterPath shape() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    off64_t FrameCount() const;

    void saveFrames(QString path);
    void saveFrames(QString path, int startFrame, int frameNo);
    IplImage* getImageData() {return buf;}
    void getFrameData(off64_t frameNo, char* data);
    
signals:
    
public slots:
    void onTimeStampUpdated(off64_t iframe);

private:
    void readFrame(off64_t iframe);
    void clamp(char* array);

    FILE * m_fp;
    QString *m_Filename;
    IplImage *buf;
    IplQImage *imageData;
    const off64_t BLOCKSIZE;
    const int STRBLOCKSIZE;
    off64_t m_FrameCount;
    QString *m_CurrentTimeStamp;
    int m_Width;
    int m_Height;
    int m_ImageWidth;
    int m_ImageHeight;

//    char strbuf[STRBLOCKSIZE];
};

#endif // GRAPHICSIMAGEITEM_H
